package com.tju.resource.oauth.controller.tb;

import com.tju.resource.annotation.Log;
import com.tju.resource.business.tb_app_log.TbAppLogService;
import com.tju.resource.model.TbShipment;
import com.tju.resource.business.tb_shipment.TbShipmentService;
import com.tju.resource.result.Result;
import com.tju.resource.tool.enum_utils.FunctionType;
import com.tju.resource.tool.tool.ClientParameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 出货管理
 */
@RestController
public class TbShipmentController {
    private final static String prefix = "ship/";
    @Autowired
    private TbShipmentService tbShipmentService;
    @Autowired
    private TbAppLogService tbAppLogService;
    /**
     * 查询出货
     * @param parameters
     * @return
     */
    @PostMapping(prefix + "list")
    @PreAuthorize("hasAuthority('sys:goods:ship:list')")
    @Log(type = FunctionType.List)
    public Result<Object> selectShipment(@RequestBody ClientParameters parameters) {
        return tbShipmentService.selectShipment(parameters);
    }

    /**
     * 添加出货
     * @param shipment
     * @return
     */
    @PostMapping(prefix + "add")
    @PreAuthorize("hasAuthority('sys:goods:ship:add')")
    @Log(type = FunctionType.Add)
    public Result<Object> insertShipment(@RequestBody TbShipment shipment) {
        return tbShipmentService.insertShipment(shipment);
    }

    /**
     * 修改出货
     * @param shipment
     * @return
     */
    @PostMapping(prefix + "edit")
    @PreAuthorize("hasAuthority('sys:goods:ship:edit')")
    @Log(type = FunctionType.Modify)
    public Result<Object> updateShipment(@RequestBody TbShipment shipment) {
        return tbShipmentService.updateShipment(shipment);
    }

    /**
     * 删除出货
     * @param shipment
     * @return
     */
    @PostMapping(prefix + "delete")
    @PreAuthorize("hasAuthority('sys:goods:ship:delete')")
    @Log(type = FunctionType.Delete)
    public Result<Object> deleteShipment(@RequestBody TbShipment shipment) {
        return tbShipmentService.deleteShipment(shipment);
    }

    /**
     * 审核出货
     * @param shipment
     * @return
     */
    @PostMapping(prefix + "approve")
    @PreAuthorize("hasAuthority('sys:goods:ship:twoApprove')")
    @Log(type = FunctionType.SecondInstance)
    public Result<Object> approveShipment(@RequestBody TbShipment shipment) {
        return tbShipmentService.approveShipment(shipment);
    }
    /**
     * 添加耗材在出货下面
     * @param shipment
     * @return
     */
    @PostMapping(prefix + "shipConsumables")
    @PreAuthorize("hasAuthority('sys:goods:ship:add')")
    @Log(type = FunctionType.Add)
    public Result<Object> shipConsumables(@RequestBody TbShipment shipment) {
        return tbShipmentService.shipConsumables(shipment);
    }
    /**
     * 审核耗材
     */
    @PostMapping(prefix + "approveShipConsumables")
    @PreAuthorize("hasAuthority('sys:goods:ship:approve')")
    @Log(type = FunctionType.FirstInstance)
    public Result<Object> approveShipConsumables(@RequestBody TbShipment shipment) {
        return tbShipmentService.approveShipConsumables(shipment);
    }
    /**
     * 查询审核记录
     */
    @PostMapping(prefix + "selectApprove")
    @PreAuthorize("hasAuthority('sys:goods:ship:auditRecords')")
    @Log(type = FunctionType.List)
    public Result<Object> selectApprove(@RequestBody Map<String,String> map) {
        return tbAppLogService.selectTbAppLogByShipmentId(map);
    }

}
